package keeto.com.vn.bms.network.task;

import java.io.IOException;

import org.apache.http.client.ClientProtocolException;
import org.json.JSONException;

import keeto.com.vn.bms.config.IBMSConfig;
import keeto.com.vn.bms.config.IBMSCore;
import keeto.com.vn.bms.network.request.GetListSurgeryRequest;
import keeto.com.vn.bms.network.response.GetListSurgeryResponse;
import keeto.com.vn.bms.utils.BMSListener;

public class TaskGetListSurgery extends AbstractTask{
	int Sortby;
	int Groupby;
	String ObjId;
	String authKey;
	int pagelimit;
	int pagenumber;

	public TaskGetListSurgery(BMSListener listener, IBMSCore core,int sortby,int groupby,String Objid,String Authkey,int pageLimit,int pageNumber) {
		super(listener, core);
		// TODO Auto-generated constructor stub
		this.Sortby = sortby;
		this.Groupby = groupby;
		this.ObjId = Objid;
		this.authKey = Authkey;
		this.pagelimit = pageLimit;
		this.pagenumber = pageNumber;
	}

	@Override
	public void run() throws ClientProtocolException, JSONException,
			IOException {
		// TODO Auto-generated method stub
		GetListSurgeryRequest request = new GetListSurgeryRequest();
		request.setSortby(Sortby);
		request.setGroupby(Groupby);
		request.setObjID(ObjId);
		request.setPagelimit(pagelimit);
		request.setPagenumber(pagenumber);
		request.setAuthKey(authKey);
		GetListSurgeryResponse response = protocol.getListSurgery(request);
		for (BMSListener mListener : listener){
			mListener.finishGetListSugery(response.getReturnCode(), response.getCountPage(), response.getListSurgeryModels());
		}
		
	}

	@Override
	public void timeoutCallback() {
		// TODO Auto-generated method stub
		for (BMSListener mListener : listener){
			mListener.finishGetListSugery(protocol.STATUS_CODE_GENERIC_FAIL_CONECTTION,IBMSConfig.UNINITIALIZED_INT, null);
		}
	}

}
